﻿'Imports MySql.Data.MySqlClient
Imports System.Globalization
Imports clsEncriptar

Module mdlGeneral
    Public cn As ConexionMySQL.ConexionMySQL
    Public sql As String
    Public sqlConsulta As String
    Public sqlModificacion As String
    Public varIdUsuarioSistema As Integer
    'Public Consulta As String Se dejo de usar cuando corregi el error de multiples consultas con frmConsultas y se utiliza la variable publica varConsulta

    Public varUcUsuarios As ucUsuarios
    Public varUcTratadoras As ucTratadoras

    Public varEmpresa As String

    Public varIdTratadora As Integer
    Public varNombreTratadora As String
    Public varTituloTratadora As String


    Sub main()

        'Obtengo los valores del App.conf
        Dim servidor, bd, usuario, contraseña As String
        Dim encriptacion As New Encriptacion

#If DEBUG Then
        servidor = encriptacion.Desencriptar(System.Configuration.ConfigurationManager.AppSettings("servidor_test"))
        bd = encriptacion.Desencriptar(System.Configuration.ConfigurationManager.AppSettings("bd_test"))
        usuario = encriptacion.Desencriptar(System.Configuration.ConfigurationManager.AppSettings("usuario_test"))
        contraseña = encriptacion.Desencriptar(System.Configuration.ConfigurationManager.AppSettings("contraseña_test"))
        varEmpresa = System.Configuration.ConfigurationManager.AppSettings("empresa_test")
#Else
        servidor = encriptacion.Desencriptar(System.Configuration.ConfigurationManager.AppSettings("servidor"))
        bd = encriptacion.Desencriptar(System.Configuration.ConfigurationManager.AppSettings("bd"))
        usuario = encriptacion.Desencriptar(System.Configuration.ConfigurationManager.AppSettings("usuario"))
        contraseña = encriptacion.Desencriptar(System.Configuration.ConfigurationManager.AppSettings("contraseña"))
        varEmpresa = System.Configuration.ConfigurationManager.AppSettings("empresa")
#End If

        '-------------------------------------

        'Creo una instancia de clsConexion con los datos del servidor y la base de datos
        'cn = New clsConexion.clsConexion("grupotec.no-ip.org", "accesorios", "sa", "30142836")

        'cn = New clsConexion.clsConexion(servidor, bd, usuario, contraseña)
        cn = New ConexionMySQL.ConexionMySQL(servidor, bd, usuario, contraseña)

        'Fuerzo configuración regional para que se muestren los decimales con punto
        System.Threading.Thread.CurrentThread.CurrentCulture = New System.Globalization.CultureInfo("es-AR")
        System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy"
        System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortTimePattern = "HH:mm:ss"
        System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyDecimalSeparator = "."
        System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyGroupSeparator = ","
        System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator = "."
        System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberGroupSeparator = ","

        'Dim oldDecimalSeparator As String = Application.CurrentCulture.NumberFormat.NumberDecimalSeparator
        'Dim forceDotCulture As CultureInfo
        'forceDotCulture = Application.CurrentCulture.Clone()
        'forceDotCulture.NumberFormat.NumberDecimalSeparator = "."
        'forceDotCulture.NumberFormat.NumberGroupSeparator = ","
        'Application.CurrentCulture = forceDotCulture
        '----------------------------------------------------------------------------

        'Abro MDIProncipal
        'Application.Run(New mnuPrincipal)
        Application.Run(New frmLogin)

        If varIdUsuarioSistema <> 0 Then
            Application.Run(New mnuPrincipal)
        End If

    End Sub

    Public Sub DatosGuardadosCorrectamente()
        MsgBox("Datos guardados correctamente", MsgBoxStyle.OkOnly + vbInformation, "Proceso exitoso")
    End Sub

    Public Sub MensajeError()
        MsgBox(Err.Description, MsgBoxStyle.OkOnly + vbCritical, "Error: " & Err.Number)
    End Sub

End Module
